package com.plata.base.aclr.utils;

public class CpuUtils {
    private static final String TAG = "CpuUtils";

    public static final String CPU_ABI_ARM32 = "arm";
    public static final String CPU_ABI_ARM64 = "arm64";
    public static final String CPU_ABI_X86_32 = "x86";
    public static final String CPU_ABI_X86_64 = "x86_64";
    public static final String CPU_ABI_MIPS32 = "mips";
    public static final String CPU_ABI_MIPS64 = "mips64";

    private static String sCpuAbi;

    static {
        initCpuAbi();
    }

    private static void initCpuAbi() {
        String cpuAbi = android.os.Build.CPU_ABI;
        String cpuAbi2 = android.os.Build.CPU_ABI2;
        LogTool.i(TAG, "initCpuAbi. CPU_ABI(%s), CPU_ABI2(%s)", cpuAbi, cpuAbi2);
        if (StringUtils.isEmpty(cpuAbi)) {
            sCpuAbi = CPU_ABI_ARM32;
            return;
        }

        if (cpuAbi.startsWith("mips")) {
            sCpuAbi = cpuAbi.contains("64") ? CPU_ABI_MIPS64 : CPU_ABI_MIPS32;
            return;
        }

        if (cpuAbi.startsWith("x86")) {
            if (!StringUtils.isEmpty(cpuAbi2) && cpuAbi2.startsWith("arm")) {
                sCpuAbi = cpuAbi.contains("64") ? CPU_ABI_ARM64 : CPU_ABI_ARM32;
                return;
            }
            sCpuAbi = cpuAbi.contains("64") ? CPU_ABI_X86_64 : CPU_ABI_X86_32;
            return;
        }

        sCpuAbi = cpuAbi.contains("64") ? CPU_ABI_ARM64 : CPU_ABI_ARM32;
    }

    public static String getCpuAbi() {
        return sCpuAbi;
    }

    public static boolean isArm() {
        return CPU_ABI_ARM32.equals(sCpuAbi) || CPU_ABI_ARM64.equals(sCpuAbi);
    }

    public static boolean isArm64() {
        return CPU_ABI_ARM64.equals(sCpuAbi);
    }
}
